package com.parse.util;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;

import com.parse.api.WebComponet;
import com.parse.bean.ProduceResultDTO;
import com.parse.core.WebComponetImpl;
import com.parse.starter.ParseApplication;
import com.parse.starter.order.OrderActivity;

/**
 * 下載工具
 * 
 * @author Andy
 * 
 */
public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
	private static final String TAG = "DownloadImage";
	private WebComponet webComponet = null;
	private ImageView image;
	private Activity ac;
	private String path;

	public DownloadImage(ImageView image, Context ct) {
		this.image = image;
		this.ac = (Activity) ct;
		this.webComponet = new WebComponetImpl();

	}

	@Override
	protected void onPreExecute() {
		// this.image.setImageResource(R.drawable.download);
		super.onPreExecute();
	}

	@Override
	protected Bitmap doInBackground(String... params) {

		this.path = (String) params[0];
		try {

			return webComponet.getBitmapScale(path, 0.4f);

		} catch (OutOfMemoryError e) {
			Log.v(TAG, "OutOfMemoryError error=" + e);
			return null;
		} catch (Exception e) {
			Log.v(TAG, "error=" + e);
			return null;
		}
	}

	@Override
	protected void onPostExecute(Bitmap result) {

		if (result == null) {

		} else {
			this.image.setImageBitmap(result);

		}

		super.onPostExecute(result);
	}

	@Override
	protected void onCancelled() {

		super.onCancelled();
	}

}
